//=======================================================
//AUTHOR: JEFF XL. ZHANG ARIZONA STATE UNIVERSITY
//ALL RIGHTS RESERVED  2008
//=======================================================
#pragma once
//#ifndef		//potential replacement for pragma once
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <math.h>
#include <vector>
#include <stdio.h>
#include <iostream>
#include "Line.h"

//#define LINE_DETAIL 1;
//#define FLAG 0;
using namespace std;

//===============================================================================
class JF_Line: public Line
{
public:
	CvPoint Pt1;
	CvPoint Pt2;
	int index;
	JF_Line();	//default
	JF_Line(CvPoint pt1, CvPoint pt2);
    
	bool on_line(CvPoint pt);
	void set_point1(CvPoint pt);
	void set_point2(CvPoint pt);
	double report_slope() const;
	double report_length() const;
	CvPoint get_cent()const;

   
private:
	int _a,_b,_c;
	bool _Verticleness;	// 0-horizontal, 1-vertical
	double _Length,_Slope,_Intercept;
	void compute_length();
	void compute_slope();
	void compute_intercept();
};

JF_Line::JF_Line(){
	//DEFAULT CONSTRUCTOR
}

void JF_Line::set_point1(CvPoint pt){
	Pt1 = pt;
}

void JF_Line::set_point2(CvPoint pt){
	Pt2 = pt;
}

JF_Line::JF_Line(CvPoint pt1, CvPoint pt2){
	Pt1 = pt1;
	Pt2 = pt2;
	this->compute_length();
	this->compute_slope();
	this->compute_intercept();
}

double JF_Line::report_length(void) const{
	return _Length;
}

void JF_Line::compute_length(void){
	_Length = sqrt(pow((Pt1.x - Pt2.x),2.0) + pow((Pt1.y - Pt2.y), 2.0));
//	cout<<"Length = "<<_Length<<endl;
}

void JF_Line::compute_slope(void){
	_Slope = (Pt2.x != Pt1.x)?((double)(Pt2.y - Pt1.y)/(Pt2.x - Pt1.x)):999999;
//	cout<<"Slope = "<<_Slope<<endl;
}

void JF_Line::compute_intercept(){
	_Intercept = (double)(Pt1.x * Pt2.y - Pt2.x * Pt1.y)/(Pt1.x - Pt2.x);
//	cout<<"Intercept = "<<_Intercept<<endl;
}
	
double JF_Line::report_slope(void) const{
	return _Slope;
}

CvPoint JF_Line::get_cent()const{
	return cvPoint((Pt1.x+Pt2.x)/2, (Pt1.y + Pt2.y)/2);
}
